package org.eclipse.emf.extensions;

import org.eclipse.emf.cdo.server.internal.db.DBAnnotation;
import org.eclipse.emf.db.util.DBModelInformationCache;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.util.EcoreUtil;

public class DBModelFieldDescriptor extends DBNativeFieldDescriptor {
    private final EStructuralFeature feature;

    public DBModelFieldDescriptor(IDBSchema schema, EStructuralFeature feature) {
        super(schema.getColumnName(feature), feature.getEType());
        this.feature=feature;
    }

    public EStructuralFeature getFeature() {
        return feature;
    }

    @Override
    boolean isAttribute() {
        return feature instanceof EAttribute;
    }

    @Override
    boolean hasInheritance() {
        return DBModelInformationCache.hasInheritance(feature);
    }

    @Override
    String getColumnTypeAnnotation() {
        return EcoreUtil.getAnnotation(feature, DBAnnotation.SOURCE_URI, DBAnnotation.COLUMN_TYPE);
    }

    @Override
    String getColumnLengthAnnotation() {
        return EcoreUtil.getAnnotation(feature, DBAnnotation.SOURCE_URI, DBAnnotation.COLUMN_LENGTH);
    }
}
